package com.reins.bookstore.entity;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

@Data
@Entity
@Table(name = "orders")
@JsonIgnoreProperties(value = {"handler","hibernateLazyInitializer","fieldHandler"})
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "orderId")
public class Orders {

    @Id
    @Column(name = "order_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int orderId;
    @Column(name = "user_id")
    private int userId;
    @Column(name = "order_time")
    private Date orderTime;
//
    @JsonIgnoreProperties(value = {"orders"})
    @OneToMany(fetch = FetchType.LAZY,targetEntity = OrderItem.class, mappedBy = "orders")
    private List<OrderItem> orderlines = new ArrayList<>();

    @JsonIgnoreProperties(value = {"orderses"})
    @ManyToOne(fetch = FetchType.LAZY,targetEntity = UserAuth.class)
    @JoinColumn(name = "user_id",referencedColumnName = "user_id",insertable = false,updatable = false)
    private UserAuth userAuth;


    public Orders(int orderId , int userId){
        this.orderId = orderId;
//        this.userId = userId;
    }
    public Orders(int orderId , int userId, Date orderTime){
        this.orderId = orderId;
//        this.userId = userId;
        this.orderTime = orderTime;
    }

    public Orders(Integer o, Integer userId, Date orderTime) {
        this.userId = userId;
        this.orderTime = orderTime;
    }

    public Orders() {

    }

//    @Override
//    public String toString(){
//        return "Orders [orderId="+orderId+", userId"+userId+", orderTime="+orderTime+"]";
//    }

}
